package com.travel.bootmall.configuration;

import com.travel.bootmall.bean.User;
import com.travel.bootmall.dao.UserDao;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Auther: yjw
 * @Date: 2020/04/11/10:33
 * @Description:
 */
public class UserRealm extends AuthorizingRealm {

    @Autowired
    UserDao userDao;
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        System.out.println("授权");
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        System.out.println("认证");
        String name = "袁佳伟";
        String password = "123456";

        UsernamePasswordToken userToken = (UsernamePasswordToken) token;
        User user = userDao.findByName(userToken.getUsername());
        if (user == null){
            return null;
        }

        return new SimpleAuthenticationInfo("",user.getPassword(),"");
    }
}
